package com.smart.community.property.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.smart.community.property.enums.BillingFeeTypeEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 计费方式VO
 * 
 * @author Wu.Liang
 * @since 2025-01-30
 * @version 1.0.0
 */
@Data
@Schema(description = "计费方式VO")
public class BillingMethodVO {

    @Schema(description = "计费方式ID")
    private Long id;

    @Schema(description = "物业公司ID")
    private Long propertyCompanyId;

    @Schema(description = "物业公司名称")
    private String propertyCompanyName;

    @Schema(description = "费用类型：property-物业费，sanitation-卫生费，gas-燃气费，water-水费，electricity-电费")
    private String feeType;

    @Schema(description = "费用类型显示文本")
    private String feeTypeText;

    @Schema(description = "建筑类型名称：如\"住宅楼\"、\"商业楼\"、\"办公楼\"、\"综合楼\"等，NULL表示适用于所有建筑类型")
    private String buildingTypeName;

    @Schema(description = "建筑类型显示文本")
    private String buildingTypeDisplayText;

    @Schema(description = "计费方式名称")
    private String methodName;

    @Schema(description = "计费类型：0-按面积计费，1-固定费用，2-阶梯计费，3-按表计费，4-阶梯电价")
    private Integer methodType;

    @Schema(description = "计费类型显示文本")
    private String methodTypeText;

    @Schema(description = "单价（元/㎡或元/m³或元/kWh等）")
    private BigDecimal unitPrice;

    @Schema(description = "固定金额（元）")
    private BigDecimal fixedAmount;

    @Schema(description = "阶梯配置JSON格式")
    private String tierConfig;

    @Schema(description = "计费方式描述")
    private String description;

    @Schema(description = "状态：0-禁用，1-启用")
    private Integer status;

    @Schema(description = "状态显示文本")
    private String statusText;

    @Schema(description = "排序")
    private Integer sortOrder;

    @Schema(description = "创建人ID")
    private Long createBy;

    @Schema(description = "创建人姓名")
    private String createByName;

    @Schema(description = "创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createTime;

    @Schema(description = "更新时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime updateTime;

    @Schema(description = "备注")
    private String remark;

    /**
     * 获取费用类型代码
     * 
     * @return 费用类型代码
     */
    public String getFeeTypeCode() {
        return feeType;
    }

    /**
     * 获取费用类型枚举
     * 
     * @return 费用类型枚举
     */
    public BillingFeeTypeEnum getFeeTypeEnum() {
        return BillingFeeTypeEnum.getByCode(this.feeType);
    }

    /**
     * 设置费用类型（String类型，供MyBatis映射使用）
     * 
     * @param feeType 费用类型字符串
     */
    public void setFeeType(String feeType) {
        this.feeType = feeType;
    }

    /**
     * 设置费用类型枚举（重命名方法避免MyBatis类型转换冲突）
     * 
     * @param feeType 费用类型枚举
     */
    public void setFeeTypeEnum(BillingFeeTypeEnum feeType) {
        this.feeType = feeType != null ? feeType.getCode() : null;
    }

    /**
     * 获取费用类型显示文本
     * 
     * @return 费用类型显示文本
     */
    public String getFeeTypeText() {
        BillingFeeTypeEnum feeTypeEnum = getFeeTypeEnum();
        return feeTypeEnum != null ? feeTypeEnum.getDescription() : "未知";
    }

    /**
     * 获取建筑类型显示文本
     * 
     * @return 建筑类型显示文本
     */
    public String getBuildingTypeDisplayText() {
        if (buildingTypeName == null || buildingTypeName.trim().isEmpty()) {
            return "适用于所有建筑类型";
        }
        return buildingTypeName;
    }

    /**
     * 获取计费类型显示文本
     * 
     * @return 计费类型显示文本
     */
    public String getMethodTypeText() {
        if (methodType == null) {
            return "未知";
        }
        switch (methodType) {
            case 0:
                return "按面积计费";
            case 1:
                return "固定费用";
            case 2:
                return "阶梯计费";
            case 3:
                return "按表计费";
            case 4:
                return "阶梯电价";
            default:
                return "未知";
        }
    }

    /**
     * 获取状态显示文本
     * 
     * @return 状态显示文本
     */
    public String getStatusText() {
        if (status == null) {
            return "未知";
        }
        return Integer.valueOf(1).equals(status) ? "启用" : "禁用";
    }
}
